hypercall.arg[0] = cmd;
hypercall.arg[1] = (unsigned long) arg;
- if (mlock(arg, arg_size) != 0) {
- PERROR("xc_acm_op: arg mlock failed");
+ if (lock_pages(arg, arg_size) != 0) {
+ PERROR("xc_acm_op: arg lock failed");
goto out;
}
ret = do_xen_hypercall(xc_handle, &hypercall);
- safe_munlock(arg, arg_size);
+ unlock_pages(arg, arg_size);
out:
return ret;
}
arg.domain_id = domid;
arg.reason = reason;
- if ( mlock(&arg, sizeof(arg)) != 0 )
+ if ( lock_pages(&arg, sizeof(arg)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out1;
ret = do_xen_hypercall(xc_handle, &hypercall);
- safe_munlock(&arg, sizeof(arg));
+ unlock_pages(&arg, sizeof(arg));
out1:
return ret;
(uint8_t *)&cpumap);
domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8;
- if ( mlock(&cpumap, sizeof(cpumap)) != 0 )
+ if ( lock_pages(&cpumap, sizeof(cpumap)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out;
ret = do_domctl(xc_handle, &domctl);
- safe_munlock(&cpumap, sizeof(cpumap));
+ unlock_pages(&cpumap, sizeof(cpumap));
out:
return ret;
(uint8_t *)cpumap);
domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8;
- if ( mlock(cpumap, sizeof(*cpumap)) != 0 )
+ if ( lock_pages(cpumap, sizeof(*cpumap)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out;
ret = do_domctl(xc_handle, &domctl);
- safe_munlock(cpumap, sizeof(*cpumap));
+ unlock_pages(cpumap, sizeof(*cpumap));
out:
return ret;
int ret = 0;
DECLARE_SYSCTL;
- if ( mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
+ if ( lock_pages(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
return -1;
sysctl.cmd = XEN_SYSCTL_getdomaininfolist;
else
ret = sysctl.u.getdomaininfolist.num_domains;
- if ( munlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
- ret = -1;
+ unlock_pages(info, max_domains*sizeof(xc_domaininfo_t));
return ret;
}
domctl.u.vcpucontext.vcpu = (uint16_t)vcpu;
set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
- if ( (rc = mlock(ctxt, sizeof(*ctxt))) != 0 )
+ if ( (rc = lock_pages(ctxt, sizeof(*ctxt))) != 0 )
return rc;
rc = do_domctl(xc_handle, &domctl);
- safe_munlock(ctxt, sizeof(*ctxt));
+ unlock_pages(ctxt, sizeof(*ctxt));
return rc;
}
domctl.u.vcpucontext.vcpu = vcpu;
set_xen_guest_handle(domctl.u.vcpucontext.ctxt, ctxt);
- if ( (rc = mlock(ctxt, sizeof(*ctxt))) != 0 )
+ if ( (rc = lock_pages(ctxt, sizeof(*ctxt))) != 0 )
return rc;
rc = do_domctl(xc_handle, &domctl);
- safe_munlock(ctxt, sizeof(*ctxt));
+ unlock_pages(ctxt, sizeof(*ctxt));
return rc;
hypercall.arg[0] = cmd;
hypercall.arg[1] = (unsigned long)arg;
- if ( mlock(arg, arg_size) != 0 )
+ if ( lock_pages(arg, arg_size) != 0 )
{
- PERROR("do_evtchn_op: arg mlock failed");
+ PERROR("do_evtchn_op: arg lock failed");
goto out;
}
if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
ERROR("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d", ret);
- safe_munlock(arg, arg_size);
+ unlock_pages(arg, arg_size);
out:
return ret;
}
arg.domid = dom;
arg.index = param;
arg.value = value;
- if ( mlock(&arg, sizeof(arg)) != 0 )
+ if ( lock_pages(&arg, sizeof(arg)) != 0 )
{
PERROR("Could not lock memory for set parameter");
return;
}
rc = do_xen_hypercall(handle, &hypercall);
- safe_munlock(&arg, sizeof(arg));
+ unlock_pages(&arg, sizeof(arg));
if (rc < 0)
PERROR("set HVM parameter failed (%d)", rc);
}
goto error_out;
}
- if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
+ if ( lock_pages(&st_ctxt, sizeof(st_ctxt) ) )
{
PERROR("%s: ctxt mlock failed", __func__);
return 1;
memset(&st_ctxt, 0, sizeof(st_ctxt));
#endif
- if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
+ if ( lock_pages(&st_ctxt, sizeof(st_ctxt) ) )
{
- PERROR("%s: ctxt mlock failed", __func__);
+ PERROR("%s: ctxt lock failed", __func__);
return 1;
}
return 1;
}
- if (mlock(&ctxt, sizeof(ctxt))) {
+ if (lock_pages(&ctxt, sizeof(ctxt))) {
/* needed for build domctl, but might as well do early */
- ERROR("Unable to mlock ctxt");
+ ERROR("Unable to lock ctxt");
return 1;
}
goto out;
}
- if (mlock(region_mfn, sizeof(xen_pfn_t) * MAX_BATCH_SIZE)) {
- ERROR("Could not mlock region_mfn");
+ if (lock_pages(region_mfn, sizeof(xen_pfn_t) * MAX_BATCH_SIZE)) {
+ ERROR("Could not lock region_mfn");
goto out;
}
return 1;
}
- if (mlock(&ctxt, sizeof(ctxt))) {
- ERROR("Unable to mlock ctxt");
+ if (lock_pages(&ctxt, sizeof(ctxt))) {
+ ERROR("Unable to lock ctxt");
return 1;
}
memset(to_send, 0xff, BITMAP_SIZE);
- if (mlock(to_send, BITMAP_SIZE)) {
- ERROR("Unable to mlock to_send");
+ if (lock_pages(to_send, BITMAP_SIZE)) {
+ ERROR("Unable to lock to_send");
return 1;
}
/* (to fix is local only) */
- if (mlock(to_skip, BITMAP_SIZE)) {
- ERROR("Unable to mlock to_skip");
+ if (lock_pages(to_skip, BITMAP_SIZE)) {
+ ERROR("Unable to lock to_skip");
return 1;
}
goto out;
}
- if (mlock(pfn_type, MAX_BATCH_SIZE * sizeof(*pfn_type))) {
- ERROR("Unable to mlock");
+ if (lock_pages(pfn_type, MAX_BATCH_SIZE * sizeof(*pfn_type))) {
+ ERROR("Unable to lock");
goto out;
}
sysctl.u.readconsole.count = nr_chars;
sysctl.u.readconsole.clear = clear;
- if ( (ret = mlock(buffer, nr_chars)) != 0 )
+ if ( (ret = lock_pages(buffer, nr_chars)) != 0 )
return ret;
if ( (ret = do_sysctl(xc_handle, &sysctl)) == 0 )
*pnr_chars = sysctl.u.readconsole.count;
- safe_munlock(buffer, nr_chars);
+ unlock_pages(buffer, nr_chars);
return ret;
}
#include <inttypes.h>
#include "xc_private.h"
-/* NB: arr must be mlock'ed */
+int lock_pages(void *addr, size_t len)
+{
+ int e = 0;
+#ifndef __sun__
+ e = mlock(addr, len);
+#endif
+ return (e);
+}
+
+void unlock_pages(void *addr, size_t len)
+{
+#ifndef __sun__
+ safe_munlock(addr, len);
+#endif
+}
+
+/* NB: arr must be locked */
int xc_get_pfn_type_batch(int xc_handle,
uint32_t dom, int num, unsigned long *arr)
{
hypercall.arg[2] = (unsigned long)0;
hypercall.arg[3] = (unsigned long)dom;
- if ( mlock(op, nr_ops*sizeof(*op)) != 0 )
+ if ( lock_pages(op, nr_ops*sizeof(*op)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out1;
ret = do_xen_hypercall(xc_handle, &hypercall);
- safe_munlock(op, nr_ops*sizeof(*op));
+ unlock_pages(op, nr_ops*sizeof(*op));
out1:
return ret;
hypercall.arg[2] = 0;
hypercall.arg[3] = mmu->subject;
- if ( mlock(mmu->updates, sizeof(mmu->updates)) != 0 )
+ if ( lock_pages(mmu->updates, sizeof(mmu->updates)) != 0 )
{
- PERROR("flush_mmu_updates: mmu updates mlock failed");
+ PERROR("flush_mmu_updates: mmu updates lock_pages failed");
err = 1;
goto out;
}
mmu->idx = 0;
- safe_munlock(mmu->updates, sizeof(mmu->updates));
+ unlock_pages(mmu->updates, sizeof(mmu->updates));
out:
return err;
case XENMEM_increase_reservation:
case XENMEM_decrease_reservation:
case XENMEM_populate_physmap:
- if ( mlock(reservation, sizeof(*reservation)) != 0 )
+ if ( lock_pages(reservation, sizeof(*reservation)) != 0 )
{
- PERROR("Could not mlock");
+ PERROR("Could not lock");
goto out1;
}
get_xen_guest_handle(extent_start, reservation->extent_start);
if ( (extent_start != NULL) &&
- (mlock(extent_start,
+ (lock_pages(extent_start,
reservation->nr_extents * sizeof(xen_pfn_t)) != 0) )
{
- PERROR("Could not mlock");
- safe_munlock(reservation, sizeof(*reservation));
+ PERROR("Could not lock");
+ unlock_pages(reservation, sizeof(*reservation));
goto out1;
}
break;
case XENMEM_machphys_mfn_list:
- if ( mlock(xmml, sizeof(*xmml)) != 0 )
+ if ( lock_pages(xmml, sizeof(*xmml)) != 0 )
{
- PERROR("Could not mlock");
+ PERROR("Could not lock");
goto out1;
}
get_xen_guest_handle(extent_start, xmml->extent_start);
- if ( mlock(extent_start,
+ if ( lock_pages(extent_start,
xmml->max_extents * sizeof(xen_pfn_t)) != 0 )
{
- PERROR("Could not mlock");
- safe_munlock(xmml, sizeof(*xmml));
+ PERROR("Could not lock");
+ unlock_pages(xmml, sizeof(*xmml));
goto out1;
}
break;
case XENMEM_add_to_physmap:
- if ( mlock(arg, sizeof(struct xen_add_to_physmap)) )
+ if ( lock_pages(arg, sizeof(struct xen_add_to_physmap)) )
{
- PERROR("Could not mlock");
+ PERROR("Could not lock");
goto out1;
}
break;
case XENMEM_translate_gpfn_list:
- if ( mlock(trans, sizeof(*trans)) != 0 )
+ if ( lock_pages(trans, sizeof(*trans)) != 0 )
{
- PERROR("Could not mlock");
+ PERROR("Could not lock");
goto out1;
}
get_xen_guest_handle(gpfn_list, trans->gpfn_list);
- if ( mlock(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
+ if ( lock_pages(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
{
- PERROR("Could not mlock");
- safe_munlock(trans, sizeof(*trans));
+ PERROR("Could not lock");
+ unlock_pages(trans, sizeof(*trans));
goto out1;
}
get_xen_guest_handle(mfn_list, trans->mfn_list);
- if ( mlock(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
+ if ( lock_pages(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
{
- PERROR("Could not mlock");
- safe_munlock(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
- safe_munlock(trans, sizeof(*trans));
+ PERROR("Could not lock");
+ unlock_pages(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
+ unlock_pages(trans, sizeof(*trans));
goto out1;
}
break;
case XENMEM_increase_reservation:
case XENMEM_decrease_reservation:
case XENMEM_populate_physmap:
- safe_munlock(reservation, sizeof(*reservation));
+ unlock_pages(reservation, sizeof(*reservation));
get_xen_guest_handle(extent_start, reservation->extent_start);
if ( extent_start != NULL )
- safe_munlock(extent_start,
+ unlock_pages(extent_start,
reservation->nr_extents * sizeof(xen_pfn_t));
break;
case XENMEM_machphys_mfn_list:
- safe_munlock(xmml, sizeof(*xmml));
+ unlock_pages(xmml, sizeof(*xmml));
get_xen_guest_handle(extent_start, xmml->extent_start);
- safe_munlock(extent_start,
+ unlock_pages(extent_start,
xmml->max_extents * sizeof(xen_pfn_t));
break;
case XENMEM_add_to_physmap:
- safe_munlock(arg, sizeof(struct xen_add_to_physmap));
+ unlock_pages(arg, sizeof(struct xen_add_to_physmap));
break;
case XENMEM_translate_gpfn_list:
get_xen_guest_handle(mfn_list, trans->mfn_list);
- safe_munlock(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
+ unlock_pages(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
get_xen_guest_handle(gpfn_list, trans->gpfn_list);
- safe_munlock(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
- safe_munlock(trans, sizeof(*trans));
+ unlock_pages(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
+ unlock_pages(trans, sizeof(*trans));
break;
}
memset(pfn_buf, 0, max_pfns * sizeof(xen_pfn_t));
#endif
- if ( mlock(pfn_buf, max_pfns * sizeof(xen_pfn_t)) != 0 )
+ if ( lock_pages(pfn_buf, max_pfns * sizeof(xen_pfn_t)) != 0 )
{
- PERROR("xc_get_pfn_list: pfn_buf mlock failed");
+ PERROR("xc_get_pfn_list: pfn_buf lock failed");
return -1;
}
ret = do_domctl(xc_handle, &domctl);
- safe_munlock(pfn_buf, max_pfns * sizeof(xen_pfn_t));
+ unlock_pages(pfn_buf, max_pfns * sizeof(xen_pfn_t));
#if 0
#ifdef DEBUG
break;
}
- if ( (argsize != 0) && (mlock(arg, argsize) != 0) )
+ if ( (argsize != 0) && (lock_pages(arg, argsize) != 0) )
{
PERROR("Could not lock memory for version hypercall");
return -ENOMEM;
rc = do_xen_version(xc_handle, cmd, arg);
if ( argsize != 0 )
- safe_munlock(arg, argsize);
+ unlock_pages(arg, argsize);
return rc;
}
errno = __saved_errno; \
} while (0)
+int lock_pages(void *addr, size_t len);
+void unlock_pages(void *addr, size_t len);
+
#define PERROR(_m, _a...) \
do { \
int __saved_errno = errno; \
hypercall.op = __HYPERVISOR_domctl;
hypercall.arg[0] = (unsigned long)domctl;
- if ( mlock(domctl, sizeof(*domctl)) != 0 )
+ if ( lock_pages(domctl, sizeof(*domctl)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out1;
" rebuild the user-space tool set?\n");
}
- safe_munlock(domctl, sizeof(*domctl));
+ unlock_pages(domctl, sizeof(*domctl));
out1:
return ret;
hypercall.op = __HYPERVISOR_sysctl;
hypercall.arg[0] = (unsigned long)sysctl;
- if ( mlock(sysctl, sizeof(*sysctl)) != 0 )
+ if ( lock_pages(sysctl, sizeof(*sysctl)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out1;
" rebuild the user-space tool set?\n");
}
- safe_munlock(sysctl, sizeof(*sysctl));
+ unlock_pages(sysctl, sizeof(*sysctl));
out1:
return ret;
set_xen_guest_handle(sysctl.u.tbuf_op.cpu_mask.bitmap, (uint8_t *)&mask);
sysctl.u.tbuf_op.cpu_mask.nr_cpus = sizeof(mask) * 8;
- if ( mlock(&mask, sizeof(mask)) != 0 )
+ if ( lock_pages(&mask, sizeof(mask)) != 0 )
{
PERROR("Could not lock memory for Xen hypercall");
goto out;
ret = do_sysctl(xc_handle, &sysctl);
- safe_munlock(&mask, sizeof(mask));
+ unlock_pages(&mask, sizeof(mask));
out:
return ret;
#include "xg_private.h"
+int lock_pages(void *addr, size_t len)
+{
+ int e = 0;
+#ifndef __sun__
+ e = mlock(addr, len);
+#endif
+ return (e);
+}
+
+void unlock_pages(void *addr, size_t len)
+{
+#ifndef __sun__
+ safe_munlock(addr, len);
+#endif
+}
+
char *xc_read_image(const char *filename, unsigned long *size)
{
int kernel_fd = -1;
#include <errno.h>
#include <string.h>
+int lock_pages(void *addr, size_t len)
+{
+ int e = 0;
+#ifndef __sun__
+ e = mlock(addr, len);
+#endif
+ return (e);
+}
+
+void unlock_pages(void *addr, size_t len)
+{
+#ifndef __sun__
+ munlock(addr, len);
+#endif
+}
+
int main(int argc, char *argv[])
{
int i, j, xc_handle;
pcv = malloc(sizeof(*pcv) * num_val);
if ( pcd == NULL
- || mlock(pcd, sizeof(*pcd) * num_desc) != 0
+ || lock_pages(pcd, sizeof(*pcd) * num_desc) != 0
|| pcv == NULL
- || mlock(pcd, sizeof(*pcv) * num_val) != 0)
+ || lock_pages(pcd, sizeof(*pcv) * num_val) != 0)
{
- fprintf(stderr, "Could not alloc or mlock buffers: %d (%s)\n",
+ fprintf(stderr, "Could not alloc or lock buffers: %d (%s)\n",
errno, strerror(errno));
exit(-1);
}
return 1;
}
- munlock(pcd, sizeof(*pcd) * num_desc);
- munlock(pcv, sizeof(*pcv) * num_val);
+ unlock_pages(pcd, sizeof(*pcd) * num_desc);
+ unlock_pages(pcv, sizeof(*pcv) * num_val);
val = pcv;
for ( i = 0; i < num_desc; i++ )